package com.example.demo_2.service;

import com.example.demo_2.dao.UserDao;
import com.example.demo_2.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    private UserDao userDao;
    
    public User login(String username, String password) {
        return userDao.getUserByName(username, password);
    }
    
    public boolean register(User user) {
        // 检查用户是否已存在
        if (userDao.findUserByName(user) > 0) {
            return false;
        }
        return userDao.creatUser(user) > 0;
    }
}
